//
//  CarTableViewController.m
//  明和智能
//
//  Created by 李李善 on 2018/8/23.
//  Copyright © 2018年 inno. All rights reserved.
//

#import "CarTableViewController.h"
#import "MainTabBarViewController.h"
#import "CarTableViewCell.h"
#import "CarDetailsTableViewController.h"
@interface CarTableViewController2 ()

@end

@implementation CarTableViewController2

- (void)viewDidLoad {
    [super viewDidLoad];
    
}
-(void)onLoadViewByWillAppear:(UIView *)view
{
    [self.tableView config:^(UITableView *tableView) {
        tableView.backgroundColor = hexCOLOR(@"EBEBEB");
        tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    }];
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    CarDetailsTableViewController *vc = [[CarDetailsTableViewController alloc]init];
    vc.tableVStyle =UITableViewStyleGrouped;
    [self pushToVC:vc model:nil hideTabBar:YES];
}

#pragma mark - Table view data source
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 10;
}

-(MCCellInfo *)tableView:(UITableView *)tableView cellForIndexPath:(NSIndexPath *)indexPath IsHeight:(BOOL)isheight
{
    return [MCCellInfo configForCellId:cell Class:[CarTableViewCell class] Height:kFitH(120) TableView:tableView];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end


@interface CarTableViewController ()

@end

@implementation CarTableViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    // Uncomment the following line to preserve selection between presentations.
    // self.clearsSelectionOnViewWillAppear = NO;
    
    // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
    // self.navigationItem.rightBarButtonItem = self.editButtonItem;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
@end



@interface CarPageViewController()<panGestureRecognizerDelegate>
@property(nonatomic,strong)UISegmentedControl *switchTabControl;
@property(nonatomic,strong)MainTabBarViewController *tabBarC;
@end

@implementation CarPageViewController

- (void)viewDidLoad {
    CarTableViewController *vc = [[CarTableViewController alloc]init];
    vc.view.backgroundColor = [UIColor redColor];
    CarTableViewController2 *vc2 = [[CarTableViewController2 alloc]initWithStyle:(UITableViewStyleGrouped)];
    vc2.view.backgroundColor = [UIColor yellowColor];
    
    MainTabBarViewController *tabBarC = [MainTabBarViewController new];
    tabBarC.panGestureDelegate = self;
    tabBarC.tabBar.hidden = YES;
    tabBarC.viewControllers = @[vc,vc2];
    [self addChildViewController:tabBarC];
    [self.view addV:tabBarC.view];
    _tabBarC = tabBarC;
    
    UISegmentedControl *segment = [[UISegmentedControl alloc]initWithItems:@[@"地图",@"列表"]];
    [segment addTarget:self action:@selector(onClickSwitchTabControl:) forControlEvents:UIControlEventValueChanged];
    [segment setSelectedSegmentIndex:0];
    segment.tintColor = [UIColor whiteColor];
    self.navigationItem.titleView =segment;
    _switchTabControl = segment;
    
    
    [super viewDidLoad];
    
    WSELF(weakSelf);
    [self onMainQueueAddSub:^(UIView *view, CGPoint origin, CGSize size, CGPoint center) {
        segment.bounds = CGRectMake(0, 0,kFitW(180),kFitH(30));
        weakSelf.tabBarC.view.frame = CGRectMake(0, 0,size.width, size.height-49);
    }];
}



-(void)onClickSwitchTabControl:(UISegmentedControl *)switchTabControl
{
    self.tabBarC.selectedIndex = switchTabControl.selectedSegmentIndex;

}

-(void)tabBarViewController:(MainTabBarViewController *)tabBarViewController SelectedIndex:(NSInteger)selectedIndex
{
        [self.switchTabControl  setSelectedSegmentIndex:selectedIndex];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
@end
